<template>
	<view>

		<view class="bg-white padding-sm">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="button"
				class="bg-white " activeColor="#00ac04"></uni-segmented-control>

			<uni-search-bar style="padding: 1px; margin-top: 20rpx;" v-model="queryForm.mobile_LIKE"
				placeholder="按id搜索会员" @blur="getList">
			</uni-search-bar>
			<uni-search-bar style="padding: 1px; ;" v-model="queryForm.realName_LIKE" placeholder="按名称搜索会员"
				@blur="getList">
			</uni-search-bar>
			<uni-search-bar style="padding: 1px; " v-model="queryForm.id2_LIKE" placeholder="按手机号搜索会员" @blur="getList">
			</uni-search-bar>
		</view>



		<view>
			<view class="margin-top-sm bg-white padding-sm " v-for="item in list">
				<view style="display: flex; justify-content: space-between;">
					<view class="font-title margin-top-sm" style="font-size: 30rpx;">{{item.realName}}</view>
					<view class="font-title font-14 margin-top-sm">类型: {{getvipTitle(item.vipId)||'无'}}</view>
				</view>
				<view style="display: flex; justify-content: space-between;">
					<view class="font-title margin-top-sm">{{item.mobile||'未设置手机号'}}</view>
					<view class="font-title font-14 margin-top-sm">id: {{item.id}}</view>
				</view>
				<view style="display: flex; justify-content: space-between;">
					<view class="font-title font-14 margin-top-sm">到期日期: {{item.vipendDate||'无'}}</view>
					<view class="font-title font-14 margin-top-sm">剩余次数: {{item.vipNumber||'无'}}</view>
				</view>
				<view style="display: flex; justify-content: space-between;" class="margin-top-sm">
					<view></view>
					<button class="login-btn cu-btn block " @click="showf(item)">修改用户</button>
				</view>

			</view>
		</view>


		<uni-popup ref="popup" type="bottom" class="padding-bottom-xl">
			<view class="padding-sm padding-bottom-xl bg-white padding-bottom-xl">
				<view class="padding-sm">修改用户</view>
				<uni-forms label-width="80px" :rules="rules" ref="baseForm" :modelValue="form">
					<uni-forms-item label="ID" required name="no">
						<uni-easyinput v-model="form.no" disabled></uni-easyinput>
					</uni-forms-item>

					<uni-forms-item label="会员类型" required name="vipId">
						<uni-data-checkbox mode="tag" :map="{text:'title',value:'number'}" v-model="form.vipId"
							:localdata="vipList"></uni-data-checkbox>
					</uni-forms-item>

					<uni-forms-item label="预约次数" required name="vipNumber">
						<uni-easyinput v-model="form.vipNumber" placeholder="预约次数 必须是整数" type="number"></uni-easyinput>
					</uni-forms-item>
					<uni-forms-item label="到期日期" required name="vipendDate">
						<uni-datetime-picker type="date" :clear-icon="false" v-model="form.vipendDate" />
					</uni-forms-item>
				</uni-forms>
				<button class="login-btn cu-btn block  bg-olive" @click="updateUserVip">保存</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		formatDate
	} from "@/utils/validate";
	import {
		getList,
		doUpdateVip
	} from "@/api/system/user/userManagement.js"
	import {
		getvipTitle
	} from "@/utils/common";
	export default {
		data() {
			return {
				items: ['会员', '非会员'],
				current: 0,
				show: false,
				list: [],
				form: {
					no: null,
					id: null,
					vipendDate: null,
					vipNumber: 0,
					vipId: null
				},
				vipList: [],
				queryForm: {
					pageNo: 1,
					pageSize: 1000,
					name_LIKE: "",
					value_LIKE: "",
					tenantId_EQ: null,
					orgIdGroup: "org_all",
					no_LIKE: null,
					vipendDate_BEGIN: formatDate(new Date),
					vipNumber_BEGIN: 1
				},
				rules: {
					vipendDate: {
						rules: [{
							required: true,
							errorMessage: '日期不能为空'
						}]
					},
					vipId: {
						rules: [{
							required: true,
							errorMessage: '会员类型不能为空'
						}]
					},
					vipNumber: {
						rules: [{
							required: true,
							errorMessage: '预约次数不能为空'
						}]
					}
				},
			}
		},
		onShow() {
			this.getList()
			this.vipList = this.$storage.getItem("miniappinfo").viplist
		},
		methods: {
			getvipTitle(id) {
				return getvipTitle(id)
				// for (var x = 0; x < this.vipList.length; x++) {
				// 	if (this.vipList[x].number == id) {
				// 		return this.vipList[x].title;
				// 	}
				// }

			},
			async updateUserVip() {
				let {
					data,
					msg
				} = await doUpdateVip(this.form)

				uni.showModal({
					title: '成功',
					content: msg,
					showCancel: false
				})
				this.getList()
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
					if (this.current == 0) {
						this.queryForm.vipendDate_BEGIN = formatDate(new Date)
						this.queryForm.vipNumber_BEGIN = 1
						this.queryForm.vipNumber_EQ = null
					} else {
						this.queryForm.vipendDate_BEGIN = null
						this.queryForm.vipNumber_BEGIN = null
						this.queryForm.vipNumber_EQ = 0
					}
					this.getList()
				}
			},
			showf(data) {
				this.form = data
				this.$refs.popup.open()
			},
			async getList() {
				let {
					data
				} = await getList(this.queryForm)
				this.list = data.rows
			},
		}
	}
</script>

<style>

</style>